package infoManage.dao;

import infoManage.domain.Teacher;

public class TeacherDao {
    private static Teacher[] teachers = new Teacher[5];
    public boolean addTeacher(Teacher teacher) { // 添加老师信息
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher tec = teachers[i];
            if(tec == null) {
                index = i;
                break;
            }
        }
        if(index == -1) {
            // 存满了
            return false;
        } else {
            teachers[index] = teacher;
            return true;
        }
    }

    public Teacher[] findAllTeacher() { // 获取老师信息
        return teachers;
    }

    public void deleteTeacher(String id) { // 删除老师信息
        int index = getIndex(id);
        teachers[index] = null;
    }

    private int getIndex(String id) { // 获取项索引
        int index = -1;
        for (int i = 0; i < teachers.length; i++) {
            Teacher tec = teachers[i];
            if(tec != null && tec.getId().equals(id)) {
                index = i;
                break;
            }
        }
        return index;
    }

    public void editTeacher(Teacher tec) { // 编辑老师信息
        int index= getIndex(tec.getId());
        teachers[index] = tec;
    }
}
